package interceptor拦截器;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 实现springmvc拦截器功能,需要实现接口
 */
public class MyInteceptor01 implements HandlerInterceptor {
    /**
     * @param request
     * @param response
     * @param handler
     * @return 返回的是boolean类型,如果返回true,拦截放行,如果false,要在preHandle中
     * 处理响应逻辑
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("preHandle执行");
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("postHanle执行");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("回调方法afterCompletion执行");
    }
}
